﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Emoney.UserTraining.BLL;
using Emoney.UserTraining.Comm;
using Emoney.UserTraining.Model;

namespace Emoney.UserTraining.Admin.aspx
{
    public partial class Export : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            Traning_NetworkMeeting_Query query = new Traning_NetworkMeeting_Query();
            query.keywords = StringTools.Request("keywords");
            string strStartDate = StringTools.Request("StartDate");
            if (!string.IsNullOrEmpty(strStartDate))
            {
                DateTime startDate = DateTime.MinValue;
                if (DateTime.TryParse(strStartDate, out startDate))
                {
                    query.StartDate = startDate;
                }
            }
            else
            {
                query.StartDate = DateTime.Now.Date.AddYears(-3);
            }
            string strEndDate = StringTools.Request("EndDate");
            if (!string.IsNullOrEmpty(strEndDate))
            {
                DateTime endDate = DateTime.MinValue;
                if (DateTime.TryParse(strEndDate, out endDate))
                {
                    query.EndDate = endDate;
                }
            }
            List<Traning_NetworkMeeting> list = new List<Traning_NetworkMeeting>();
            Traning_NetworkMeetingBLL bll = new Traning_NetworkMeetingBLL();
            list = bll.GetHistryList(query);

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("EM/EMG账号, UID内部账号, 累计收益, 仓位, 持股个数, 当前风格, 风格激活日 \r\n");
            foreach (var item in list)
            {
                sb.AppendFormat("{0}, {1}, {2}, {3}, {4}, {5}, {6}", item.txtteachar, item.txtreateachar, item.startDate, item.mtg_name, item.meeting_type, item.mtg_id, item.time_flag);
                sb.Append("\r\n");
            }

            Response.Clear();
            Response.Buffer = true;
            Response.Charset = "GB2312";
            Response.AppendHeader("Content-Disposition", "attachment;filename=SyCount.xlsx");
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
            Response.ContentType = "text/plain";//设置输出文件类型为txt文件。 

            System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
            Response.Write(sb.ToString());
            Response.End();
        }
    }
}